<template>
	<view>
		<uni-table ref="table" :loading="loading" border stripe emptyText="暂无数据">
			<uni-tr>
				<uni-th align="center">批次名</uni-th>
				<uni-th align="center">状态</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in tableData" :key="index">
				<uni-td align="center">{{ item.name }}</uni-td>
				<uni-td>
					<view align="center">{{ item.status }}</view>
				</uni-td>
			</uni-tr>
		</uni-table>
		<view class="pagination-padding">
			<uni-pagination show-icon :page-size="queryParams.pageSize" :current="queryParams.pageNum" :total="total"
				@change="getList" />
		</view>
		<!-- 选择路线查询 -->
		<SelectRoute :show.sync="selectRoute.show" :routes="selectRoute.routes" @select="getSelectList" />
	</view>
</template>

<script>
	import {
		myUnCompleteList,
		myList
	} from '@/api/orderManage/myDispatch'
	import SelectRoute from './components/selectRoute.vue'

	export default {
		components: {
			SelectRoute
		},
		data() {
			return {
				/**选择路线查询 */
				selectRoute: {
					show: false,
					routes: [],
				},
				/**表格数据 */
				tableData: [],
				/**数据总条数 */
				total: 0,
				/**表格加载状态 */
				loading: false,
				user: '',
				/**查询参数 */
				queryParams: {
					pageNum: 1,
					pageSize: 10,
				},
			};
		},
		mounted() {
			this.getList()
		},
		methods: {
			getSelectList(e) {
				console.log(e);
			},
			/** 查询列表 */
			getList() {
				myUnCompleteList().then((res) => {
					const {
						rows,
						total
					} = res
					this.tableData = rows
					this.total = total
					if (total == 0) return this.$message({
						type: 'error',
						message: this.$t('暂无派送任务')
					})
					if (total == 1) {
						const router = this.$router.resolve({
							path: '/googleMap',
							query: {
								routeId: rows[0].id,
							},
						})
						window.location.href = router.href
					}
					if (total > 1) {
						this.selectRoute.show = true
						this.selectRoute.routes = rows
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>